//
//  DdddViewController.m
//  tablede
//
//  Created by zhouhaie on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "DdddViewController.h"
#import "NewWebViewController.h"

@interface DdddViewController ()
#define height 59;
#define IP 190.168.12.98;

@end

@implementation DdddViewController

//viewController 的生命周期
- (void)viewWillAppear:(BOOL)animated{
    
}

- (void)viewDidAppear:(BOOL)animated{
    
}
- (void)viewWillDisappear:(BOOL)animated{
    
}
- (void)viewDidDisappear:(BOOL)animated{
}   


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"tableview考试";
    _arr=@[@{
             @"headerTitle":@"第1组",
             @"footer":@"第1组footer",
             @"list":@[
                       @{@"ti":@"北京",@"con":@"111",@"ima":@"01"
                         },
                       @{@"ti":@"上海",@"con":@"111",@"ima":@"01"
                         },
                       @{@"ti":@"广州",@"con":@"111",@"ima":@"01"
                         }
                      ]
               },
           
          @{
               @"headerTitle":@"第2组",
               @"footer":@"第2组footer",
               @"list":@[
                         @{@"ti":@"沈阳",@"con":@"222",@"ima":@"02"
                           },
                         @{
                           @"ti":@"大连",@"con":@"222",@"ima":@"02"
                            }
                       ]
               
               },
           @{
               @"headerTitle":@"第3组",
               @"footer":@"第3组footer",
               @"list":@[
                         @{@"ti":@"鞍山",@"con":@"333",@"ima":@"03"
                           },
                         @{
                           @"ti":@"抚顺",@"con":@"333",@"ima":@"03"
                             }
                       ]
               }
           
           ];
 //UserDefaults 存取删
 [[NSUserDefaults standardUserDefaults] setValue:@"所有内容" forKey:@"name"];
  NSArray *arr =  [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
 [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"name"];
    
    //三目运算符
    NSString *str;
    
    int i = 4;
    
    int j = 3;
    
    str = j>i?@"大于":@"小于";
    
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//cell跳转到第二页
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    NewWebViewController *vc = [[NewWebViewController alloc] init];
    //    [self.navigationController pushViewController:vc animated:YES];
    
    NSDictionary *daDic=[_arr objectAtIndex:indexPath.section];
    
    NewWebViewController * vc=[[NewWebViewController alloc]init];
    
    NSArray *listArr=daDic[@"list"];
    NSDictionary *xiaoDic=[listArr objectAtIndex:indexPath.row];
    vc.title=daDic[@"headerTitle"];
    vc.fff=xiaoDic[@"ti"];
    [self.navigationController pushViewController:vc animated:YES];
    
    //提示框
    UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要退出吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    [alrt show];
    
}
//提示框方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex == 0) {
        
        NSLog(@"fds");
        
    }else{
        
        NSLog(@"确定");
        
    }
}


//绘制header

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headervv = [[UIView alloc] init];
    headervv.frame = CGRectMake(0,0,320,59);
    headervv.backgroundColor = [UIColor redColor];
    //add label
    UILabel * lll = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 200, 21)];
    NSDictionary * dic = [_arr objectAtIndex:section];
    lll.text = dic[@"headerTitle"];
    [headervv addSubview:lll];
    return headervv;
}
//header 高度
-(CGFloat)tableView:(UITableView * )tableView heightForHeaderInSection:(NSInteger)section{
    return height;
}

//绘制footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
        UIView *footervv = [[UIView alloc] init];
        footervv.frame = CGRectMake(0,0,320,59);
        footervv.backgroundColor = [UIColor grayColor];
        //add label
        UILabel * lll = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 200, 21)];
        NSDictionary * dic = [_arr objectAtIndex:section];
        lll.text = dic[@"footer"];
        [footervv addSubview:lll];
        return footervv;
}
//footer 高度
-(CGFloat)tableView:(UITableView * )tableView heightForFooterInSection:(NSInteger)section{
    return height;
}

//section 部分
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _arr.count;}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
       NSDictionary * dic = [_arr objectAtIndex:section];
       NSArray * arr =[dic objectForKey:@"list"];
       return arr.count;
}

//写cell 部分
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *indentifier = @"xinCell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:indentifier];
    }
    NSDictionary *daDic = [_arr objectAtIndex:indexPath.section];
    NSArray *listArr = daDic[@"list"];
    NSDictionary * xiaoDic = [listArr objectAtIndex:indexPath.row];

    cell.textLabel.text =[xiaoDic objectForKey:@"ti"];
    cell.detailTextLabel.text = xiaoDic[@"con"];
    cell.imageView.image = [UIImage imageNamed:xiaoDic[@"ima"]];
    return cell;
    }
//cell 高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return height;

}







/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
